package Users;

public class User {

    private String user_name;
    private String user_pass;
    private boolean user_privileged;

    public User(String name, String pass) {
        this.user_name = name;
        this.user_pass = pass;
        this.user_privileged = false;
    }

    public User(String name, String pass, boolean privileged) {
        this.user_name = name;
        this.user_pass = pass;
        this.user_privileged = privileged;
    }

    public String getUserName() {
        return (this.user_name);
    }

    public String getUserPass() {
        return (this.user_pass);
    }

    public boolean getUserPrivileged() {
        return (this.user_privileged);
    }

    public void setUserPrivileged(boolean privileged) {
        this.user_privileged = privileged;
    }

    @Override
    public String toString() {
        return (this.user_name + ";" + this.user_pass + ";" + this.user_privileged);
    }

    @Override
    //@Abraham Este método asume que el objeto con el que se compara es de tipo User
    //y además no sobre escrito hashCode
    public boolean equals(Object user) {
        User useraux = (User) user;
        boolean usersEquals = false;
        if (this.getUserName().equals(useraux.getUserName())
                && this.getUserPass().equals(useraux.getUserPass())) {
            usersEquals = true;
        }
        return usersEquals;
    }

    public static User stringToUser(String user_data) {
        String[] data = user_data.split(";");
        boolean privileges;
        if (data[2].equals("true")) {
            privileges = true;
        } else {
            privileges = false;
        }
        User user = new User(data[0], data[1], privileges);
        return user;
    }
}
